	Hello, everyone!
	My name is Andrei Redkin and I am a QA Engineer.
	Today I'm going to tell you about Spring Boot Framework and different cases when it can help a QA Engineer in test automation.
So, at first we need to answer the question what is a Spring Boot? It is a Java Framework for creating Spring based applications. <Here will be text from official documentation>
And now let's make our first project. The best and easiest way to do this is via start.spring.io web site. Here you can set your project settings: the project name, Java version, Spring Boot version. You can also add dependencies right away. Then you just need to press Generate button and your base project will be downloaded. As you can see here this project already has a base code with empty test method.
Now let’s talk about profiles. You know that we have a lot of test stands. These stands can have different urls, different passwords to DataBases and a lot of other parameters which are same by meaning but different by value. All these parameters you can manage easily with Spring Boot.
Give a look at our project. We have an application.properties file. And when you run your Spring Boot application it will automatically scan this file for parameters. Let’s imagine that you have two test environments: dev and qa. You can create two properties files: 	application-qa.properties, application-dev.properties and in our first default file write “spring.profiles.active=dev”
or “spring.profiles.active=qa”.
<Here I show my project on screen to demonstrate>
And now when you run you project Spring will read profile name from main properties file and the it will search for application-<profile_name>.properties file to get parameters from it. Very easy. It’s also useful when you run tests from Jenkins. You can pass parameters from it and in your gradle script assign it to Spring Boot profile setting.
<Here I show my project gradle file on screen to demonstrate>
Let’s continue and talk about reading test properties.
Base code will look like this: you can init a variable with @Value annotation:
@Value("${main.url}")
Such syntax means that this variable will get a value from property "main.url".
<Here I show base code>
The more advanced way to do it is by initializing you properties in separate class.
<Here I will switch to branch 3 >
Give a look at package config. We added a PropertiesProvider class here, marked with Spring Boot annotation @Component and Lombok annotation @Getter to generate getters automatically and for the sake of simplicity of code.
Lets talk about @Component. What does it mean? <Here information from official resources>
And know with such knowledge let’s switch to our test class. As you see here we marked our PropertiesProvider with annotation @Autowired. It means that <Here information from official resources>. And know have easy access to your test properties and can switch between test environments easily.
To continue to develop our test framework we will add Selenium WebDriver to it.
<I am switching to branch 4>
Give a look at SeleniumWebDriver config class. You already can understand what happens here: depending on profile the method getWebDriver () returns Ednge or Chrome WebDriver. The new annotation for us is @Bean. It means that <Information from official documentation>.
Now lets switch to test class. As you see here we autowired our WebDriver. But you may ask how does it work? Here comes Spring Boot complex inner logic. When you run your application Spring Boot scans for all classes marked as Component and method marked as Beans. Then in our test class Spring Boot sees that we autowired a variable with type WebDriver. And it knows that in SeleniumWebDriver we have a bean which returns a WebDriver. And so it decides that webDriver variable is result of getWebDriver method. And it really works like this and sometimes looks like a magic.
Lets make add a PageObject Pattern to our framework.
<I am switching to branch 5>
Look at package with the name pages. Here we have classes for MainPage and RegistrationPage. For our example we used the randomapi.com website. And have a method for loading web page and a method for clicking the Sign Up button.
The new annotation here is @PostContruct. The official documentation says that <Description of @PostContruct  annotation>. That’s why we need it to initialize a PageFactory. RegisterPage works the same. And right now we have a simple test which loads the main page, presses Sign Up button and enters credentials.
But what if we need a bit more? What if we need to get data from some WebService? Real case example: before test run we need to generate a random user and via WebService save it DataBase. Or we need to find real client with special parameters with help of WebService and then use it in tests. And so on… We can do it in two lines of code
<I am switching to branch 6>
Give a look at test method simpleRestRequest. Here in two lines of code we perform a call to REST WebService https://randomuser.me/api (this service generates random user data for you on every call) and automatically deserialize JSON to RandomUserDTO object.
Then we can get such information like user name, phone, email by simple calling of methods. The code is simple and easy to read. Much more time you will spend by creating DTO classes for our test web services. But with help of https://www.jsonschema2pojo.org/ it can be made in no time. I am often using it.
Another way to communicate with WebServices is OpenFeign. It is a SpringBoot dependency which will help to make a calls to WebServices too.
Take a look at interface RandomUserService. @FeignClient annotation has the main url to our web service and @GetMapping annotation has a path to our method. Get also means that this is a Get request. Now need toannotate our test class with @EnableFeignClients and that’s it. Now we can call a method getRandomUser and it will return our RandomUser object. As an example we added a method inputRandomCredentials to our RegisterPage class and now our test can enter random credentials.
Let’s talk about DataBases.
<I am switching to branch 7>
Spring Boot has a lot of ways to work with DataBases. I will show you just one by using DriverManagerDataSource and JdbcTemplate.
Give a look at new properties: you can see that we made some settings for connection to postgres DataBase. Not lets go to package database. Here we have a class InitDataBase with private method for obtaining JdbcTemplate and public method executeQuery which we will use for execution of SQL statements. Also we a have a component UtilsDataBase which has an autowired InitDataBase and has a method which maps raw data from DataBase to class Client.
Let’s return to our test class. As you see here we have an autowired UtilsDataBase and use it for grtting client data from DataBase.
And we came to our last case: using Kafka. Kafka is a Message Broker <here goes information from official resources>
In my practice I needed to connect to Kafka for reading messages which System-Under-Test sent during work. Query “Spring Boot Kafka” to Google gave me a lot of resources and told about dependency ‘org.springframework.kafka:spring-kafka'.
To start work with Kafka at first you need to get the connection data: bootstrap servers, topic name and so on. Then you need to make a class (KafkaConfig in our case) and annotate it with @EnableKafka annotation. Take a look at consumerFactory method: it returns DefaultConsumerFactory with configuration from KafkaSettings. Then we need to create a KafkaListener: it’s a simple method with @KafkaListener annotation which has a single input parameter. This method will receive all new Kaka messages so you can can put all logic here. To make a Producer is even more easy. Take a look at our test class. You just need to autowire a Kafka Template and then call method send with topic name and data to send. That’s it.
<Here comes presentation slide with useful links>

